package com.liuxinlong.common;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liuxinlong.enums.ReturnCodes;
import com.liuxinlong.modules.common.controller.response.BaseResp;

import lombok.extern.slf4j.Slf4j;

/**
 * 异常处理器
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-01-14
 */
@ControllerAdvice
@Slf4j
public class AosExceptionHandler {
	
		/**
		 * 系统自定义异常处理
		 * 
		 * @param e 异常信息
		 * @return 通用返回信息
		 */
		@ExceptionHandler(AosException.class)
		@ResponseBody
		public BaseResp aosExceptionHandler(AosException e){
			BaseResp resp = new BaseResp();
			resp.setRetCode(e.getErrorCode());
			resp.setRetMessage(e.getErrorMsg());
	       	return resp;
	    }
	
		/**
		 * 系统异常处理
		 * 
		 * @param e 异常信息
		 * @return 返回信息
		 */
	 	@ExceptionHandler(Exception.class)
	 	@ResponseBody
		public BaseResp exceptionHandler(Exception e){
	 		log.error("系统运行异常：",e);
	 		BaseResp resp = new BaseResp(); 
			resp.setRetCode(ReturnCodes.HTTP_SYSTEM_ERROR.getRetCode());
			resp.setRetMessage(ReturnCodes.HTTP_SYSTEM_ERROR.getMsg());
	       	return resp;
	    }
}
